import random

import pygame


class Gopher(pygame.sprite.Sprite):
    def __init__(self, img, dims=(720,1280), size=(200,200), position=(200,400)):
        super().__init__()
        self.dims = dims
        self.width, self.height = dims
        self.image = pygame.transform.scale(img, size)
        # self.spriteScale = pygame.transform.scale(self.image, (50, 50))
        # self.image.fill((random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))
        self.rect = self.image.get_rect()

        self.rect = (position[0], position[1])
        self.speed_y = random.randint(4, 10)
        self.moveLength=0
        self.direction = 'up'

    def update(self):
        if self.direction == 'up':
            self.rect = (self.rect[0], self.rect[1] - 1)
            self.moveLength +=1
        if self.direction == 'down':
            self.rect = (self.rect[0], self.rect[1] + 1)
            self.moveLength -=1
        if self.moveLength>70:
            self.direction = 'down'
        if self.moveLength<0:
            return False
        else:
            return True


    def draw(self, screen):
        screen.blit(self.image, self.rect)